import {
  upload,
  addExpense,
  addIncome,
  queryUserExpensePageByUid,
  queryUserIncomePageByUid,
  queryUserExpenseDetailsInfo,
  queryUserIncomeDetailsInfo,
  searchUserExpenseMonthView,
  searchUserIncomeMonthView,
  exportUserExpenseMonthViewToExcel,
  exportUserIncomeMonthViewToExcel,
  getUserExpenseMonthChartInfo,
  getUserIncomeMonthChartInfo
} from '@/api/bills/billls'

const actions = {
  upload({commit, state}, formData) {
    return new Promise((resolve, reject) => {
      upload(formData).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  addExpense({commit, state}, expense) {
    return new Promise((resolve, reject) => {
      addExpense(expense).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  addIncome({commit, state}, income) {
    return new Promise((resolve, reject) => {
      addIncome(income).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryUserExpensePageByUid({commit, state}, page) {
    const {uid, currentPageNum} = page;
    return new Promise((resolve, reject) => {
      queryUserExpensePageByUid(uid, currentPageNum).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryUserIncomePageByUid({commit, state}, page) {
    const {uid, currentPageNum} = page;
    return new Promise((resolve, reject) => {
      queryUserIncomePageByUid(uid, currentPageNum).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryUserExpenseDetailsInfo({commit, state}, id) {
    return new Promise((resolve, reject) => {
      queryUserExpenseDetailsInfo(id).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryUserIncomeDetailsInfo({commit, state}, id) {
    return new Promise((resolve, reject) => {
      queryUserIncomeDetailsInfo(id).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  searchUserExpenseMonthView({commit, state}, page) {
    const {uid, realName, month, currentPageNum} = page;
    return new Promise((resolve, reject) => {
      searchUserExpenseMonthView(uid, realName, month, currentPageNum).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  searchUserIncomeMonthView({commit, state}, page) {
    const {uid, realName, month, currentPageNum} = page;
    return new Promise((resolve, reject) => {
      searchUserIncomeMonthView(uid, realName, month, currentPageNum).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  exportUserExpenseMonthViewToExcel({commit, state}, page) {
    const {uid, realName, month, currentPageNum} = page;
    return new Promise((resolve, reject) => {
      exportUserExpenseMonthViewToExcel(uid, realName, month, currentPageNum).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  exportUserIncomeMonthViewToExcel({commit, state}, page) {
    const {uid, realName, month, currentPageNum} = page;
    return new Promise((resolve, reject) => {
      exportUserIncomeMonthViewToExcel(uid, realName, month, currentPageNum).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  getUserExpenseMonthChartInfo({commit, state}, page) {
    const {type, uid, realName, month} = page;
    return new Promise((resolve, reject) => {
      getUserExpenseMonthChartInfo(type, uid, realName, month).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },
  getUserIncomeMonthChartInfo({commit, state}, page) {
    const {type, uid, realName, month} = page;
    return new Promise((resolve, reject) => {
      getUserIncomeMonthChartInfo(type, uid, realName, month).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  }
}

export default {
  actions
}
